/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
package robocup.component.tactics;

import robocup.component.PConf;
import robocup.component.coach.PlayerTypeAnalyzer;
import robocup.component.geometry.Vektor;
import robocup.component.worldobjects.Player.ROLE;

/**
 * A class containing all start positions.
 */
public class FormationData {

	/**
	 * This method retrieves the Start-Position of a player depending on his
	 * player's role.
	 * 
	 * @param role - the players role
   * @param selfKickOff - true when it's our kick off, false otherwise
	 * @return a vektor containing the position
	 */
	public static Vektor getStartPosition(ROLE role, boolean selfKickOff) {

		int xy = Vektor.XY;

		switch (role) {
		case GOALIE:
			return new Vektor(xy, 0.0, -50);
		case INLE_BACK_FOUR:
			return new Vektor(xy, -7.0, -15.0);
		case INRE_BACK_FOUR:
			return new Vektor(xy, 7.0, -15.0);
		case LEFT_BACK_FOUR:
			return new Vektor(xy, -20.0, -15.0);
		case RIGHT_BACK_FOUR:
			return new Vektor(xy, 20.0, -15.0);
		case CENTER_MIDFIELD:
			return new Vektor(xy, 0.0, -12.0);
		case LEFT_MIDFIELD:
			return new Vektor(xy, -20.0, -6.0);
		case RIGHT_MIDFIELD:
			return new Vektor(xy, 20.0, -6.0);
		case LEFT_ATTACKER:
			return new Vektor(xy, -10.0, -2.0);
		case CENTER_ATTACKER:
			if (selfKickOff)
				return new Vektor(xy, 0.0, -3.1);
			else
				return new Vektor(xy, 0.0, -9.0);
		case RIGHT_ATTACKER:
			return new Vektor(xy, 10.0, -2.0);
		default:
			return new Vektor(xy, 25.0, 25.0);
		}
	}
  
  /**
   * This method decides which hetero-playertype will be associated with the
   * player with number i
   * 
   * @param i -
   *            the number of the player
   * @param types -
   *            a list containing all available types 3 times, initially.
   *            Selected type will be removed!
   * @return the PConf, which was selected!
   */
  public static PConf[] getPConfForPlayers(PlayerTypeAnalyzer pta) {

    PConf[] all = pta.getAllPConf();
    PConf[] resultPConf = new PConf[11];

    int pcSize = pta.getPcSize();
    int ptypeIsAv[] = pta.getPtypeIsAv();

    // Ranked Values from PConf
    // KM: Kickable Margin
    // DP: Dash Power Rate
    // IM: Inertia Moment
    // St: Extra Stamina
    // int ranked_KM[] = pta.getRanked_KM();
    int ranked_DP[] = pta.getRanked_DP();
    int ranked_St[] = pta.getRanked_St();
    // int ranked_Fast[] = pta.getRanked_Fast();
    // int ranked_KM_IM[] = pta.getRanked_KM_IM();
    // int ranked_KM_St[] = pta.getRanked_KM_St();
    int ranked_DP_St[] = pta.getRanked_DP_St();
    int ranked_1DP_2St[] = pta.getRanked_1DP_2St();
    int ranked_2DP_1St[] = pta.getRanked_2DP_1St();
    int ranked_KM_DP_St[] = pta.getRanked_KM_DP_St();

    // Player assignment

    // Set Goalie
    resultPConf[0] = all[0].cloned();
    ptypeIsAv[0]++;

    // Set Player 10
    for (int i = 0; i < pcSize; i++)
      if (ptypeIsAv[ranked_DP[i]] < 3) {
        resultPConf[9] = all[ranked_DP[i]].cloned();
        ptypeIsAv[ranked_DP[i]]++;
        break;
      }

    // Set Player 4
    for (int i = 0; i < pcSize; i++)
      if (ptypeIsAv[ranked_DP[i]] < 3) {
        resultPConf[3] = all[ranked_DP[i]].cloned();
        ptypeIsAv[ranked_DP[i]]++;
        break;
      }

    // Set Player 7
    for (int i = 0; i < pcSize; i++)
      if (ptypeIsAv[ranked_KM_DP_St[i]] < 3) {
        resultPConf[6] = all[ranked_KM_DP_St[i]].cloned();
        ptypeIsAv[ranked_KM_DP_St[i]]++;
        break;
      }

    // Set Player 9
    for (int i = 0; i < pcSize; i++)
      if (ptypeIsAv[ranked_DP_St[i]] < 3) {
        resultPConf[8] = all[ranked_DP_St[i]].cloned();
        ptypeIsAv[ranked_DP_St[i]]++;
        break;
      }

    // Set Player 11
    for (int i = 0; i < pcSize; i++)
      if (ptypeIsAv[ranked_2DP_1St[i]] < 3) {
        resultPConf[10] = all[ranked_2DP_1St[i]].cloned();
        ptypeIsAv[ranked_2DP_1St[i]]++;
        break;
      }

    // Set Player 3
    for (int i = 0; i < pcSize; i++)
      if (ptypeIsAv[ranked_DP[i]] < 3) {
        resultPConf[2] = all[ranked_DP[i]].cloned();
        ptypeIsAv[ranked_DP[i]]++;
        break;
      }

    // Set Player 6
    for (int i = 0; i < pcSize; i++)
      if (ptypeIsAv[ranked_1DP_2St[i]] < 3) {
        resultPConf[5] = all[ranked_1DP_2St[i]].cloned();
        ptypeIsAv[ranked_1DP_2St[i]]++;
        break;
      }

    // Set Player 8
    for (int i = 0; i < pcSize; i++)
      if (ptypeIsAv[ranked_1DP_2St[i]] < 3) {
        resultPConf[7] = all[ranked_1DP_2St[i]].cloned();
        ptypeIsAv[ranked_1DP_2St[i]]++;
        break;
      }

    // Set Player 2
    for (int i = 0; i < pcSize; i++)
      if (ptypeIsAv[ranked_St[i]] < 3) {
        resultPConf[1] = all[ranked_St[i]].cloned();
        ptypeIsAv[ranked_St[i]]++;
        break;
      }

    // Set Player 5
    for (int i = 0; i < pcSize; i++)
      if (ptypeIsAv[ranked_St[i]] < 3) {
        resultPConf[4] = all[ranked_St[i]].cloned();
        ptypeIsAv[ranked_St[i]]++;
        break;
      }

    pta.setPtypeIsAv(ptypeIsAv);
    return resultPConf;
  }
}
